﻿using System;
using System.IO;
using Microsoft.Synchronization.Files;

namespace Microsoft.WindowsAzure.Accelerator.Synchronization
{
    /// <summary>
    /// Mechanism by which cloud sync provider and file sync provider transfer data between each other.
    /// </summary>
    internal class CloudSyncFileRetriever : IFileDataRetriever
    {
        private readonly FileData _fileData;
        private readonly Stream _fileStream;
        private readonly String _relativePath;

        /// <summary>
        /// Initializes a new instance of the <see cref="CloudSyncFileRetriever"/> class.
        /// </summary>
        /// <param name="fileData">The file data.</param>
        /// <param name="relativePath">The relative path.</param>
        /// <param name="fileStream">The file stream.</param>
        internal CloudSyncFileRetriever(FileData fileData, String relativePath, Stream fileStream)
        {
            if (fileData == null) throw new ApplicationException("File retriever issue: file data is empty.");
            if (relativePath == null) relativePath = String.Empty;
            _fileData = fileData;
            _fileStream = fileStream;
            _relativePath = relativePath;
        }

        /// <summary>
        /// Gets the absolute path to a file that is part of a replica.
        /// </summary>
        /// <value></value>
        /// <returns>The absolute path to a file that is part of a replica.</returns>
        public String AbsoluteSourceFilePath
        {
            get { throw new NotImplementedException("The absolute path property is not currently implemented."); }
        }

        /// <summary>
        /// Gets the path of the file (without the file name), relative to the root directory of the replica.
        /// </summary>
        /// <value></value>
        /// <returns>The path of the file (without the file name) relative to the root directory of the replica.</returns>
        public String RelativeDirectoryPath
        {
            get { return _relativePath; }
        }

        /// <summary>
        /// Gets a <see cref="T:Microsoft.Synchronization.Files.FileData"/> object that represents information about a file.
        /// </summary>
        /// <value></value>
        /// <returns>A <see cref="T:Microsoft.Synchronization.Files.FileData"/> object that represents information about a file.</returns>
        public FileData FileData
        {
            get { return _fileData; }
        }

        /// <summary>
        /// Gets a <see cref="T:System.IO.Stream"/> object that can be used to access the data in a file.
        /// </summary>
        /// <value></value>
        /// <returns>A <see cref="T:System.IO.Stream"/> object that can be used to access the file data.</returns>
        public Stream FileStream
        {
            get { return _fileStream; }
        }
    }
}